package main.pl.pawellinkshell.liczba;

/**
 * Klasa liczba 
 * @author Pawel
 *
 */
public class Liczba {

	/**
	 * Konstruktor domyslny
	 */
	public Liczba() {
		super();
		this.number = 0;
	}
	
	/**
	 * Konstruktor z param
	 * @param number
	 */
	public Liczba(final int number){
		super();
		this.number = number;
	}
	
	/**
	 * Metoda umozliwiajaca zwrocenie liczby w innym systemie liczbowym
	 * @param base podstawa liczbowa 
	 * @return Liczba w wybranym przez nas podstawe
	 */
	public String baseSystem (final int base){
	      if(base > Literals.Sixteen.getValue()){
	//    	  	System.out.println("Podstawa wieksza niz 16");
	    	  	return null;
	      }
	      if(base < Literals.Two.getValue()){
	 //   	  	System.out.println("Podstawa mniejsza niz 2");
	    	  	return null;
	      }
	      if(base == Literals.Ten.getValue()){
	          return  Integer.toString(number);
	      }
	      else
	      {
	          int helper;
	          int localNumber = number;
	          StringBuilder reverseSB = new StringBuilder("");
	          while(localNumber != Literals.Zero.getValue())
	          {
	              helper = localNumber % base;
	              localNumber /= base; 
	              if(helper == Literals.Zero.getValue()){
	            	  reverseSB.append('0');
	              }
	              if(helper == Literals.One.getValue()){
	            	  reverseSB.append('1');
	              }
	              if(helper == Literals.Two.getValue()){
	            	  reverseSB.append('2');
	              }
	              if(helper == Literals.Three.getValue()){
	            	  reverseSB.append('3');
	              }
	              if(helper == Literals.Four.getValue()){
	            	  reverseSB.append('4');
	              }
	              if(helper == Literals.Five.getValue()){
	            	  reverseSB.append('5');
	              }
	              if(helper == Literals.Six.getValue()){
	            	  reverseSB.append('6');
	              }
	              if(helper == Literals.Seven.getValue()){
	            	  reverseSB.append('7');
	              }
	              if(helper == Literals.Eight.getValue()){
	            	  reverseSB.append('8');
	              }
	              if(helper == Literals.Nine.getValue()){
	            	  reverseSB.append('9');
	              }
	              if(helper == Literals.Ten.getValue()){
	            	  reverseSB.append('A');
	              }
	              if(helper == Literals.Eleven.getValue()){
	            	  reverseSB.append('B');
	              }
	              if(helper == Literals.Twelve.getValue()){
	            	  reverseSB.append('C');
	              }
	              if(helper == Literals.Thirteen.getValue()){
	            	  reverseSB.append('D');
	              }
	              if(helper == Literals.Fourteen.getValue()){
	            	  reverseSB.append('E');
	              }
	              if(helper == Literals.Fifteen.getValue()){
	            	  reverseSB.append('F');
	              }
	          }
				return reverseSB.reverse().toString();
	      } 
	   }
	
	/**
	 * Metoda sprawdzajaca czy pole number ma wartosc 0
	 * @return
	 */
	public boolean isZero(){
		return (this.number == Literals.Zero.getValue()) ? false : true;
	}
	
	/**
	 * Mutator do pola number
	 * @return
	 */
	public int getNumber() {
		return number;
	}

	/**
	 * Akcesor do pola number
	 * @param number
	 */
	public void setNumber(final int number) {
		this.number = number;
	}
	
	/**
	 * Metoda testujaca
	 * @param args
	 */
	public static void main(final String[] args) {
		final Liczba num = new Liczba(10);
		
		for (int i = 2; i < 16; i++) {
			System.out.println(num.baseSystem(i));
		}
	}
	
	/**
	 * Pole przechowujaca wartosc
	 */
	private int number;
	
	/**
	 * Typ enumeryczny dla literalow
	 * @author Pawel
	 */
	private enum Literals { 
		Zero(0) , One(1), Two(2), Three(3), Four(4), Five(5), Six(6), Seven(7), Eight(8), Nine(9), Ten(10), 
		Eleven(11), Twelve(12), Thirteen(13), Fourteen(14), Fifteen(15), Sixteen(16);
		
		private Literals(final int value){
			this.value = value;
		}
		
		/**
		 * Akcesor do pola value dla enuma Literals
		 * @return
		 */
		public int getValue() {
			return value;
		}

		/**
		 * Pole dla literalu
		 */
		private int value;
	};
}


